package com.zzyang.cloud.controller;

import com.zzyang.cloud.lb.MyLoadBalance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * TODO
 *
 * @author zhuoziyang
 * @date 2020/10/22 21:52
 */
@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private MyLoadBalance myLoadBalance;

    private final String URL = "http://CLOUD-PAYMENT-SERVICE";

    @GetMapping("/order/get")
    public String get() {

        ServiceInstance serviceInstance = myLoadBalance.choose();

        return restTemplate.getForObject("http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/payment/get", String.class);
    }

}
